package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.mapper.ReportBookMapper;
import com.itheima.service.ReportBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Description:
 * @Version: V1.0
 */
@Service(interfaceClass = ReportBookService.class)
@Transactional
public class ReportBookServiceImpl implements ReportBookService {
    @Autowired
    private ReportBookMapper reportBookMapper;

    @Override
    public List<String> findDate(List<Date> dateValue) {
        Date startDate = dateValue.get(0);
        Date endDate = dateValue.get(1);
        List<Date> dates = reportBookMapper.findDate(startDate,endDate);
        List<String> list=new ArrayList<>();
        if(dates!=null && dates.size()>0){
            for (Date date : dates) {
                list.add(new SimpleDateFormat("yyyy-MM-dd").format(date));
            }
        }
        return list;
    }


    @Override
    public List<String> findAllDate() {
        List<Date> dates = reportBookMapper.findAllDate();
        List<String> list=new ArrayList<>();
        if(dates!=null && dates.size()>0){
            for (Date date : dates) {
                list.add(new SimpleDateFormat("yyyy-MM-dd").format(date));
            }
        }
        return list;
    }

    @Override
    public Integer findBookAllByDate(String date) {
        return reportBookMapper.findBookAllByDate(date);
    }

    @Override
    public Integer findBookOnByDate(String date) {
        return reportBookMapper.findBookOnByDate(date);
    }



}
